package org.apache.servicecomb.samples.practise.houserush.user.center.dao;

import org.apache.servicecomb.samples.practise.houserush.user.center.aggregate.House;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author: Snake Man
 * @system:
 * @DateTime: 2022/1/1 12:58
 * @Description:
 */
public interface HouseDao extends JpaRepository<House, Integer> {

    //根据id批量查询房源
    @Query("select h from House h where h.id in (?1)")
    List<House> findAllByIdForUpdate(List<Integer> ids);

    //根据id批量修改房源状态为锁定
    @Modifying
    @Query("update House h set h.state = 'locking' where h.id in (?1)")
    int updateLockingStatesForUpdate(List<Integer> ids);

    //根据id批量解锁房源，房源的状态为new
    @Modifying
    @Query("update House h set h.state = 'new' where h.id in (?1)")
    int updateReleaseLockingStattesForHouses(List<Integer> ids);
}
